package com.doubao.user.client;

import com.doubao.common.result.Result;
import com.doubao.user.client.fallback.PaymentClientFallback;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 支付服务客户端
 */
@FeignClient(name = "doubao-wechat", path = "/wechat", fallback = PaymentClientFallback.class)
public interface PaymentClient {

    /**
     * 创建支付订单
     *
     * @param userId     用户ID
     * @param productId  商品ID
     * @param amount     支付金额（分）
     * @param subject    商品标题
     * @param body       商品描述
     * @param payChannel 支付渠道
     * @param payType    支付类型
     * @param attach     附加数据
     * @param clientIp   客户端IP
     * @return 支付订单信息
     */
    @PostMapping("/pay/create-order")
    Result<Map<String, Object>> createOrder(
            @RequestHeader("X-User-ID") Long userId,
            @RequestParam("productId") Long productId,
            @RequestParam("amount") Integer amount,
            @RequestParam("subject") String subject,
            @RequestParam("body") String body,
            @RequestParam("payChannel") String payChannel,
            @RequestParam("payType") String payType,
            @RequestParam("attach") String attach,
            @RequestParam("clientIp") String clientIp);

    /**
     * 查询订单
     *
     * @param userId          用户ID
     * @param outTradeNo      商户订单号
     * @return 订单信息
     */
    @GetMapping("/pay/query/{outTradeNo}")
    Result<Map<String, Object>> getOrderByOutTradeNo(
            @RequestHeader("X-User-ID") Long userId,
            @PathVariable("outTradeNo") String outTradeNo);

    /**
     * 关闭订单
     *
     * @param userId     用户ID
     * @param outTradeNo 商户订单号
     * @return 关闭结果
     */
    @PostMapping("/pay/close/{outTradeNo}")
    Result<Void> closeOrder(
            @RequestHeader("X-User-ID") Long userId,
            @PathVariable("outTradeNo") String outTradeNo);

    /**
     * 创建会员支付订单
     *
     * @param userId      用户ID
     * @param membershipId 会员ID
     * @param amount      支付金额（分）
     * @param payType     支付类型
     * @param clientIp    客户端IP
     * @return 支付订单信息
     */
    @PostMapping("/membership/pay")
    Result<Map<String, Object>> createMembershipOrder(
            @RequestHeader("X-User-ID") Long userId,
            @RequestParam("membershipId") Long membershipId,
            @RequestParam("amount") Integer amount,
            @RequestParam("payType") String payType,
            @RequestParam("clientIp") String clientIp);

    /**
     * 查询会员订单
     *
     * @param outTradeNo 商户订单号
     * @param userId     用户ID
     * @return 订单信息
     */
    @GetMapping("/membership/pay/order/{outTradeNo}")
    Result<Map<String, Object>> queryMembershipOrder(
            @PathVariable("outTradeNo") String outTradeNo,
            @RequestHeader("X-User-ID") Long userId);

    /**
     * 会员订单支付回调
     *
     * @param outTradeNo    商户订单号
     * @param transactionId 微信支付订单号
     * @param userId        用户ID
     * @return 处理结果
     */
    @PostMapping("/membership/callback/{outTradeNo}")
    Result<Void> handlePaymentCallback(
            @PathVariable("outTradeNo") String outTradeNo,
            @RequestParam("transactionId") String transactionId,
            @RequestHeader("X-User-ID") Long userId);
} 